﻿Imports System
Imports System.IO

Public Class frmBasicPatternExtract
    Dim patterns() As BasicPatternAbstraction
    Dim curPattern As Long
    Private Sub frmBasicPatternExtract_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ReDim patterns(0)
        patterns(0) = New BasicPatternAbstraction
        curPattern = 0
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim rs As StreamReader
        ofd.Filter = "All Files|*.*"
        ofd.ShowDialog()
        txtFile.Text = ofd.FileName
        rs = New StreamReader(txtFile.Text)
        rtxtFile.Text = rs.ReadToEnd
        rs.Close()
    End Sub

    Private Sub rtxtFile_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtxtFile.SelectionChanged
        Label2.Text = "Selected: " & rtxtFile.SelectionLength
  
    End Sub
    Private Sub Change_RTF_Color(ByRef ctrl As RichTextBox)
        Dim pIndex As Long, pLength As Long
        pIndex = ctrl.SelectionStart
        pLength = ctrl.SelectionLength
        ctrl.SelectionStart = 1
        ctrl.SelectionLength = Len(ctrl.Text)
        ctrl.SelectionColor = Color.Black
        ctrl.SelectionStart = pIndex
        ctrl.SelectionLength = pLength
    End Sub

    Private Sub rtxtFile_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtxtFile.TextChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ReDim Preserve patterns(UBound(patterns) + 1)
        patterns(UBound(patterns)) = New BasicPatternAbstraction
        curPattern = UBound(patterns)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Change_RTF_Color(rtxtFile)

        rtxtFile.SelectionColor = Color.Blue
        patterns(curPattern).Update_Pattern(rtxtFile.SelectedText)
        rtxtPattern.Text = patterns(curPattern).Pattern
    End Sub
End Class